import React, { Component } from 'react';
import '../styles/Collection.css';
import { NavBar } from 'antd-mobile';
import { good_favlist, good_unfav } from '../api';


class Collection extends Component {
    componentDidMount() {
        good_favlist({ userid: localStorage.getItem("userid") }).then((res) => {
            console.log(res)
            this.setState({
                favlist: res.data.list
            })
        })

    }
    back() {
        this.props.history.push('index/mine')
    }

    unfav(id) {
        good_unfav({ userid: localStorage.getItem("userid"), goodid: id }).then((res) => {
            console.log(res.data)
            good_favlist({ userid: localStorage.getItem("userid") }).then((res) => {
                console.log(res)
                this.setState({
                    favlist: res.data.list
                })
            })
        })
        console.log(id);

    }

    toDetail(id) {
        this.props.history.push('/detail/'+id)
    }

    render() {
        return (
            <div className='collectionbox'>
                <NavBar back='返回' onBack={back}>
                    我的收藏
                </NavBar>
                <div className='box'  onClick={()=>{this.toDetail(item.id)}}>
                    <div className='pic'>
                        <img src={pic} alt="" />
                    </div>
                    <div className='other'>
                        <div className='name'>商品</div>
                        <div className='price-cancel'>
                            <div className='price'>
                            价格:{item.salesPrice.value}
                            </div>
                            <div className="cancel" onClick={(e) => {
                                this.unfav(item.id, e)
                            }}>取消收藏</div>
                        </div>
                    </div>
                </div>
            </div>

        );
    }
}

export default Collection;